﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UFramework.Tools;
using System.IO;
using UDebug = UnityEngine.Debug;
using NPOI.SS.UserModel;

namespace UFramework.Editor
{
    public class MyEditor
    {
        //打开Data目录
        [MenuItem("Tools/Folders/DataPath")]
        public static void OpenDataPath()
        {
            Application.OpenURL(Application.dataPath);
        }
        //打开StreamingAssets目录
        [MenuItem("Tools/Folders/StreamingAssetsPath")]
        public static void OpenStreamingAssetsPath()
        {
            FileHelper.CreatDirBeforeWrite(Application.streamingAssetsPath);
            Application.OpenURL(Application.streamingAssetsPath);
        }
        //打开PersistentData目录 (持久化目录)
        [MenuItem("Tools/Folders/PersistentDataPath")]
        public static void OpenPersistentDataPath()
        {
            FileHelper.CreatDirBeforeWrite(Application.persistentDataPath);
            Application.OpenURL(Application.persistentDataPath);
        }

        //打开PersistentData目录 (持久化目录)
        [MenuItem("Tools/Folders/ABPath")]
        public static void OpenABPath()
        {
            string abPath = Path.GetFullPath("./AB/");
            FileHelper.CreatDirBeforeWrite(abPath);
            Application.OpenURL(abPath);
        }

        //对AB目录生下的Android和ISO分别成文件清单,包含对应文件名和对应的MD5值
        [MenuItem("Tools/Asset/CreatFileListInABPath")]
        public static void CreatFileListWithMD5()
        {
            string ABPath = Path.GetFullPath("./AB");
            string[] plantfromPaths = Directory.GetDirectories(ABPath);
            foreach (var item in plantfromPaths)
            {
                FileHelper.CreatDirBeforeWrite(item);
                FileHelper.CreatFileListWithMD5(item, "*");
            }
            Application.OpenURL(ABPath);
        }

        [MenuItem("Tools/Excel转Json")]
        public static void ExcelToJson()
        {//可以从这类中创建 文件选择框,进度框...
            string path = EditorUtility.OpenFilePanel("请选择Excel文件", null, "xlsx,xls");
            Debug.Log("你选择的是:" + path);
            //代码

            IWorkbook wbk = ExcelHelper.ReadWorkBook(path);
            ISheet sheet = wbk.GetSheetAt(0);
            string jsonStr = ExcelHelper.ExcelToJson(sheet);
            Debug.Log(jsonStr);
        }

        [MenuItem("Tools/Test/Test1")]
        public static void Test1()
        {
        }
    }
}